<?php

/**
 * @name Template
 */

class TemplateException extends Exception{}

class Template
{
    /**
     * @var Widget
     */
    public $widget = array();


    protected $_vars = array();

    public function setWidget(Widget $widget)
    {
        $widget->setTemplate($this);
        $this->widget[$widget->name] = $widget;
    }
    /*
        @tpl:即时渲染 & 延迟渲染
            $this->getWidget('tagcloud')->render(); class TagCloud_Widget extends Widget
            $this->getWidget('comment')->delayRender(); class Comment_Widget extends Widget
    */
    public function getWidget($name)
    {
        // or $this->widget[$name] instanceof Widget
        if (isset($this->widget[$name]) && is_object($this->widget[$name]))
            return $this->widget[$name];
        else
            throw new TemplateException();
    }

    /**
     *
     *
     */
    public function assign($name, $value = NULL)
    {

    }

    public function fetch()
    {

    }

    public function display()
    {

    }
}

?>